﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using StructureMap;
using GraphCompiler.Core.SyntaxRepresentation;
using GraphCompiler.Core.Parsing;
using GraphCompiler.Core.Infrastructure;

namespace GraphCompiler.Specification.Infrastructure
{
    [TestFixture]
    public class IocBootstrapperSpecs : SpecificationBase
    {
        [Test]
        public void GivenAutoWiredParser_IsParser()
        {
            var parser = ObjectFactory.GetInstance<Parser>();

            Assert.IsInstanceOfType(typeof(Parser), parser);
        }

        [Test]
        public void GivenAutoWiredParser_HasDiagramParser()
        {
            Parser parser = ObjectFactory.GetInstance<Parser>();

            var diagramParser = parser.ChildParsers.OfType<DiagramParser>().Single();

            Assert.IsNotNull(diagramParser);
        }

        [Test]
        public void GivenAutoWiredDiagramParser_IsDiagramParser()
        {
            var diagramParser = ObjectFactory.GetInstance<ITypedParser<DiagramNode>>();

            Assert.IsInstanceOfType(typeof(DiagramParser), diagramParser);
        }

        [Test]
        public void GivenAutoWiredDiagramParser_HasBoxParser()
        {
            var diagramParser = ObjectFactory.GetInstance<ITypedParser<DiagramNode>>();

            var concreteDiagramParser = (DiagramParser)diagramParser;
            var boxParser = concreteDiagramParser.ChildParsers.OfType<BoxParser>().Single();

            Assert.IsNotNull(boxParser);
        }

        [Test]
        public void GivenAutoWiredDiagramParser_HasArrowParser()
        {
            var diagramParser = ObjectFactory.GetInstance<ITypedParser<DiagramNode>>();

            var concreteDiagramParser = (DiagramParser)diagramParser;
            var boxParser = concreteDiagramParser.ChildParsers.OfType<ArrowParser>().Single();

            Assert.IsNotNull(boxParser);
        }
    }
}
